package bavaria.hightech.statement;

import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.Locale;
import java.util.ResourceBundle;

import bavaria.hightech.banking.Account;
import bavaria.hightech.banking.Transaction;

public class StatementFormatterTextPlain implements IStatementFormatter {

	private StringBuffer sb;
	ResourceBundle bundle;
	Locale currentLocale;
	NumberFormat numberFormatter;
	DateFormat dateFormatter;
	
	public StatementFormatterTextPlain(Locale currentLocale){
		this.currentLocale = currentLocale;
		bundle = ResourceBundle.getBundle("props/local", currentLocale);
		numberFormatter = NumberFormat.getCurrencyInstance(currentLocale);
		dateFormatter = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, 
				DateFormat.DEFAULT, currentLocale);
		sb = new StringBuffer();
	}
	
	public void setCurrentLocale(Locale currentLocale) {
		this.currentLocale = currentLocale;
	}

	@Override
	public void addAccountData(Account account) {
		sb.append(bundle.getString("KONTONUMMER") + ": " + account.getAccountNumber()+ "\n");
		sb.append(bundle.getString("INHABER") + ": " + account.getDepositor()+ "\n");
		sb.append(bundle.getString("KONTOSTANDNEU") + ": " + numberFormatter.format(
				account.getAccountBalance()) + "\n\n");
		
	}

	@Override
	public void addTransaction(Transaction transaction) {
		sb.append(bundle.getString("DATUM") + ": " + dateFormatter.format(transaction.getTime()) + "\n");
		sb.append(bundle.getString("GRUND") + ": " + transaction.getReason() + "\n");
		sb.append(bundle.getString("BETRAG") + ": " + numberFormatter.format(transaction.getMoney().getValue()) +  "\n\n");
		
	}

	@Override
	public void addAccountBalance(long accountBalance) {
		sb.append(bundle.getString("KONTOSTANDNEU") + ": " + numberFormatter.format(accountBalance) + "\n\n");
	}
	
	public String getFormattedText(){
		return sb.toString();
	}

}
